import service from '../utils/axios'
import type { ApiResponse } from '../utils/axios'

// 班级数据接口
export interface ClassInfo {
  id: number
  name: string
  majorId: number
  createBy?: string
  createTime?: string
  updateBy?: string
  updateTime?: string
}

// 分页查询参数接口
interface ClassQueryParams {
  name?: string
  majorId?: number
  page?: number
  size?: number
}

// 分页查询响应接口
interface PageResult<T> {
  data: T[]
  total: number
  page: number
  size: number
}

// 创建/更新班级请求接口
interface ClassRequest {
  name: string
  majorId: number
}

/**
 * 根据专业ID获取班级列表（用于下拉选择）
 */
export function getClassesByMajor(majorId: number): Promise<ApiResponse<ClassInfo[]>> {
  return service({
    url: `/api/classes/major/${majorId}`,
    method: 'get'
  })
}

/**
 * 获取班级列表（分页）
 */
export function getClassList(data: ClassQueryParams): Promise<ApiResponse<PageResult<ClassInfo>>> {
  return service({
    url: '/api/classes/query',
    method: 'post',
    data
  })
}

/**
 * 获取班级详情
 */
export function getClassById(id: number): Promise<ApiResponse<ClassInfo>> {
  return service({
    url: `/api/classes/${id}`,
    method: 'get'
  })
}

/**
 * 创建班级
 */
export function createClass(data: ClassRequest): Promise<ApiResponse<{ id: number }>> {
  return service({
    url: '/api/classes',
    method: 'post',
    data
  })
}

/**
 * 更新班级
 */
export function updateClass(id: number, data: ClassRequest): Promise<ApiResponse<void>> {
  return service({
    url: `/api/classes/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除班级
 */
export function deleteClass(id: number): Promise<ApiResponse<void>> {
  return service({
    url: `/api/classes/${id}`,
    method: 'delete'
  })
}